package main

import (
	"time"
	"fmt"
	"os"
)

func main() {
	pipe := make(chan int)
	epip := make(chan string)
	go func() {
		for i := 0; i < 4; i++ {
			pipe <- i
			fmt.Fprintf(os.Stdout, "子进程数值：%d\n", i)
			time.Sleep(1 * time.Second)
		}
		close(pipe)
		ser, err := <- epip
		if ! err {
			fmt.Printf("接受发生错误：%v\n", err)
			os.Exit(1)
		}
		fmt.Printf("接收到父进程消息：%s\n", ser)
	}()

	for {
		res, e := <- pipe
		if ! e {break}
		fmt.Printf("父进程接受数值：%d 状态[%v]\n", res, e)
	}
	<-pipe
	time.Sleep(2 * time.Second)
	epip <- "结束请求"
	time.Sleep(2 * time.Second)
}